<?
require_once("cls_db.php");

class cls_sales
{	
	
	function insert_usertrack($arr)
	{
		$db		= new db();
		$sql	= "INSERT INTO tbl_usertrack(user_id,coordinator_id,brand,type,qty,unitprice,total) VALUES ('". $_SESSION['id'] ."','". $arr['coordinator_id'] ."','". $arr['brand'] ."','". $arr['type'] ."','". $arr['qty'] ."','". $arr['price'] ."','". $arr['qty']  * $arr['price'] ."')";
		//echo $sql;
		return $db->execute_nonquery($sql);
		
	}
	
	function item_count($id)
	{
		$db 	= new db();
		$sql = "SELECT SUM(qty) AS total FROM tbl_usertrack WHERE user_id = '$id'";
		
		$row = $db->get_count($sql);

		if (count($row)) {
			return $row;
		}
	}
	
	function total_price($id)
	{
		$db 	= new db();
		$sql = "SELECT SUM(total) AS total FROM tbl_usertrack WHERE user_id = '$id'";
		
		$row = $db->get_count($sql);

		if (count($row)) {
			return $row;
		}
	}
	
	function grand_total($id)
	{
		$db 	= new db();
		$sql = "SELECT SUM(total) AS total FROM tbl_usertrack WHERE user_id = '$id'";
		
		$row = $db->get_count($sql);

		if (count($row)) {
			return $row;
		}
	}
	
	function get_usertrack_salesinfo()
	{
		$db 	= new db();
		$sql	= "INSERT INTO tbl_salesinfo(user_id,coordinator_id,brand,type,qty,unitprice,total) SELECT tbl_usertrack.user_id,tbl_usertrack.coordinator_id,tbl_usertrack.brand,tbl_usertrack.type,tbl_usertrack.qty,tbl_usertrack.unitprice,tbl_usertrack.total FROM tbl_usertrack";

		return $db->execute_nonquery($sql);
		
	}	
	
	function get_salesinfo($id)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_usertrack WHERE user_id  = '$id'";

		$row = $db->get_all_data($sql);

		if (count($row)) {
			return $row;
		}
	}
	
	function delete_usertrack()
	{
		$db 	= new db();
		$sql	= "DELETE FROM tbl_usertrack";

		return $db->execute_nonquery($sql);
	}
	
	function delete_product_list($id)
	{
		$db		= new db();
		
		$sql = "Delete from tbl_usertrack where id = $id";
			
		return $db->execute_nonquery($sql);
		
		echo  $sql;
		
		
	}
	
		
}//class
?>